<template>
  <div :class="['config', { right_hide: !show }]" :style="`width:${toolbarWidth}px`">
    <ConfigGrid :id="id" v-show="type === 'grid'" />
    <ConfigNode :id="id" v-show="type === 'node'" />
    <ConfigEdge :id="id" v-show="type === 'edge'" />
    <FoldBtn direction="right" v-model:show="show" />
  </div>
</template>

<script lang="ts" setup>
import { toolbarWidth } from '../../config/index';
import FoldBtn from '../FoldBtn.vue';
import ConfigGrid from './ConfigGrid.vue';
import ConfigNode from './ConfigNode.vue';
import ConfigEdge from './ConfigEdge.vue';
import { FlowGraph } from '../../common/FlowGraph';
import { ref } from 'vue';

const show = ref(true)

const type = ref('grid');
const id = ref('');
const { graph } = FlowGraph;
graph.on('blank:click', () => {
  type.value = 'grid';
});
graph.on('cell:click', ({ cell }) => {
  type.value = cell.isNode() ? 'node' : 'edge';
  id.value = cell.id;
});

graph.on('cell:mouseenter', ({ cell }) => {
  cell.addTools('button-remove')
});

graph.on('cell:mouseleave', ({ cell }) => {
  cell.removeTool('button-remove')
});
</script>

<style lang="scss" scoped>
.config {
  height: calc(100% - 40px);
  padding: 0 10px;
  position: absolute;
  top: 40px;
  right: 0;
  z-index: 100;
  transition: 0.4s;
  box-sizing: border-box;
  border-left: 1px solid #d9d9d9;
}

.right_hide {
  right: -280px;
  transition: 0.4s;
}
</style>
